using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace SunshineFarmWord
{
    public class PlayerReelingState : PlayerFishingBaseState
    {
        private float _reelTimeMax = 0;
        public PlayerReelingState(PlayerStateMachine playerStateMachine) : base(playerStateMachine)
        {
        }

        #region base function 
        public override void Enter()
        {
            base.Enter();

            InitReelingReusableData();

            _reelTimeMax = Random.Range(stateMachine.ReusableData.PlayerStatesData.PlayerFishingData.FishReelingTimeMin, stateMachine.ReusableData.PlayerStatesData.PlayerFishingData.FishReelingTimeMax);

            StartAnimation(stateMachine.Player.AnimationData.ReelingParameterHash);
        }

        public override void Exit()
        {
            base.Exit();

            StopAnimation(stateMachine.Player.AnimationData.ReelingParameterHash);
        }

        public override void OnAnimationExitEvent()
        {
            base.OnAnimationExitEvent();

            //stateMachine.ChangeState(stateMachine.CaughtState);
        }

        public override void Update()
        {
            base.Update();

            ChangeReelingCountDown();
            // 
            ChangeReelingTime();
        }
        #endregion


        #region Main Function
        private void ChangeReelingTime()
        {
            if (stateMachine.ReusableData.PlayerStatesData.PlayerFishingData.FishReelingTime < _reelTimeMax)
            {
                stateMachine.ReusableData.PlayerStatesData.PlayerFishingData.FishReelingTime += Time.deltaTime;
            }
            else
            {
                stateMachine.ReusableData.PlayerStatesData.PlayerFishingData.CaughtItFish = false;
                stateMachine.ChangeState(stateMachine.CaughtState);
            }
        }

        //点击进行增加
        private void ClickReelingCountAdd()
        {
            stateMachine.ReusableData.PlayerStatesData.PlayerFishingData.FishReelingCountDown += stateMachine.ReusableData.PlayerStatesData.PlayerFishingData.FishReelingAddNumber;
        }
        // 根据时间而减少
        private void ChangeReelingCountDown()
        {
            if (stateMachine.ReusableData.PlayerStatesData.PlayerFishingData.FishReelingCountDown <= 0) return;
            stateMachine.ReusableData.PlayerStatesData.PlayerFishingData.FishReelingCountDown -= Time.deltaTime;
            if (stateMachine.ReusableData.PlayerStatesData.PlayerFishingData.FishReelingCountDown < 0) stateMachine.ReusableData.PlayerStatesData.PlayerFishingData.FishReelingCountDown = 0;
        }

        #endregion


    }
}
